
import java.math.BigDecimal;
import java.math.MathContext;


/**
 * @author Nizar
 *
 */

public class MinusBinExpr extends BinExpr {

	public MinusBinExpr(Expr leftExpr, Expr rightExpr) {
		super(leftExpr, rightExpr);

	}

	@Override
	public BigDecimal evaluate(Env env) {
		return leftExpr.evaluate(env).subtract(rightExpr.evaluate(env), MathContext.DECIMAL128);
	}

	@Override
	public String toString(){
		String leftExprTmp = leftExpr.toString();
		String rightExprTmp = "("+rightExpr.toString()+")";

		if(leftExpr.isAssignExpr())
			leftExprTmp = "("+leftExprTmp+")";
		if(rightExpr.isUnExpr() || rightExpr.isNum() || rightExpr.isId())
			rightExprTmp = rightExpr.toString();

		return leftExprTmp+" - "+rightExprTmp;
	}

	@Override
	public boolean isUnExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isAssignExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isPlusBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isMinusBinExpr() {
		// TODO Auto-generated method stub
		return true;
	}

	@Override
	public boolean isTimesBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isDivideBinExpr() {
		// TODO Auto-generated method stub
		return false;
	}


	@Override
	public boolean isNum() {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean isId() {
		// TODO Auto-generated method stub
		return false;
	}

	public static MinusBinExpr _(Expr leftExpr, Expr rightExpr ) {
		// TODO Auto-generated method stub
		return new MinusBinExpr(leftExpr, rightExpr);
	}

	@Override
	public boolean isSeqExpr() {
		// TODO Auto-generated method stub
		return false;
	}

}
